2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
9 namespace SuperPolarity
14 protected Texture2D Texture;
15 protected Vector2 Origin;
18 // Physical Properties
19 protected Vector2 Position;
20 protected Vector2 Velocity;
21 protected Vector2 Acceleration;
22 protected float Angle;
24 // Constraints / Behavior
25 protected float MaxVelocity;
26 protected float AccelerationRate;
30 get { return Texture.Width; }
35 get { return Texture.Height; }
38 public virtual void Initialize(ContentManager Content, Texture2D texture, Vector2 position)
44 Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
45 Velocity = new Vector2(0, 0);
46 Acceleration = new Vector2(0, 0);
49 AccelerationRate = 10;
52 public void AutoDeccelerate(GameTime gameTime)
54 if (Acceleration.X == 0 && Velocity.X > 0)
56 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.X)
63 Acceleration.X = -AccelerationRate;
67 if (Acceleration.X == 0 && Velocity.X < 0)
69 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.X)
76 Acceleration.X = AccelerationRate;
80 if (Acceleration.Y == 0 && Velocity.Y > 0)
82 if (AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds > Velocity.Y)
89 Acceleration.Y = -AccelerationRate;
93 if (Acceleration.Y == 0 && Velocity.Y < 0)
95 if (-AccelerationRate * gameTime.ElapsedGameTime.TotalSeconds < Velocity.Y)
102 Acceleration.Y = AccelerationRate;
107 public virtual void Update(GameTime gameTime)
113 public void Move(GameTime gameTime)
115 AutoDeccelerate(gameTime);
117 Velocity.X = Velocity.X + Acceleration.X * (float)gameTime.ElapsedGameTime.TotalSeconds;
118 Velocity.Y = Velocity.Y + Acceleration.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
120 if (Velocity.X > MaxVelocity)
122 Velocity.X = MaxVelocity;
125 if (Velocity.X < -MaxVelocity)
127 Velocity.X = -MaxVelocity;
130 if (Velocity.Y > MaxVelocity)
132 Velocity.Y = MaxVelocity;
135 if (Velocity.Y < -MaxVelocity)
137 Velocity.Y = -MaxVelocity;
140 Position.X = Position.X + Velocity.X;
141 Position.Y = Position.Y + Velocity.Y;
144 public void ChangeAngle()
146 Angle = (float)Math.Atan2(Velocity.Y, Velocity.X);
149 public virtual void Draw(SpriteBatch spriteBatch)
151 spriteBatch.Draw(Texture, Position, null, Color.White, Angle, Origin, 1f, SpriteEffects.None, 0f);